package com.steel.yfmall.cloud.assistant.stock.impl;

import com.steel.yfmall.cloud.assistant.dto.para.stock.ParaSteelChannelUserGroupCodeLimit;
import com.steel.yfmall.cloud.assistant.po.stock.SteelChannelUserGroupCodeLimitExample;
import com.steel.yfmall.cloud.assistant.stock.SteelChannelUserGroupCodeLimitService;
import com.steel.yfmall.cloud.assistant.stock.mapper.SteelChannelUserGroupCodeLimitMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;

/**
 * @author jia chang bao
 * @date 2021/2/23 21:05
 */
@Service
@Slf4j
public class SteelChannelUserGroupCodeLimitServiceImpl implements SteelChannelUserGroupCodeLimitService {

    /**
     * 根据 多个 userGroupCode（会员临时组编码） 批量删除
     *
     * @param paraSteelChannelUserGroupCodeLimit
     * @return true 成功，false失败
     * @author jia chang bao
     */
    @Override
    public Boolean deleteChannelUserGroupCodeLimitByList(ParaSteelChannelUserGroupCodeLimit paraSteelChannelUserGroupCodeLimit) {
        SteelChannelUserGroupCodeLimitExample steelChannelUserGroupCodeLimitExample = checkData(paraSteelChannelUserGroupCodeLimit);
        int i = steelChannelUserGroupCodeLimitMapper.deleteByExample(steelChannelUserGroupCodeLimitExample);
        if (i > 0) {
            return true;
        }
        return false;
    }

    private SteelChannelUserGroupCodeLimitExample checkData(ParaSteelChannelUserGroupCodeLimit paraSteelChannelUserGroupCodeLimit) {
        SteelChannelUserGroupCodeLimitExample steelChannelUserGroupCodeLimitExample = new SteelChannelUserGroupCodeLimitExample();
        SteelChannelUserGroupCodeLimitExample.Criteria criteria = steelChannelUserGroupCodeLimitExample.createCriteria();

        if (!CollectionUtils.isEmpty(paraSteelChannelUserGroupCodeLimit.getUserGroupCodes())) {
            criteria.andUserGroupCodeIn(paraSteelChannelUserGroupCodeLimit.getUserGroupCodes());
        }

        return steelChannelUserGroupCodeLimitExample;
    }

    @Resource
    private SteelChannelUserGroupCodeLimitMapper steelChannelUserGroupCodeLimitMapper;
}
